package com.gpnu7_412.yanzhi.service.impl;

import com.gpnu7_412.yanzhi.dto.ConciseUserDto;
import com.gpnu7_412.yanzhi.entity.Interest;
import com.gpnu7_412.yanzhi.entity.User;
import com.gpnu7_412.yanzhi.exception.custom.RequestDataException;
import com.gpnu7_412.yanzhi.mapper.InterestMapper;
import com.gpnu7_412.yanzhi.service.InterestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author HJJ
 */
@Service
public class InterestServiceImpl implements InterestService {
    @Autowired
    InterestMapper interestMapper;

    /**
     * 获取用户关注列表
     * @param userId 用户ID
     * @return 用户关注列表
     */
    @Override
    public List<User> getUserLikeList(Integer userId) {
        if (userId == null) {
            throw new RequestDataException("用户Id获取异常");
        }
        return interestMapper.selectMyInterestList(userId);
    }

    /**
     * 获取用户粉丝列表
     * @param userId 用户ID
     * @return 粉丝列表
     */
    @Override
    public List<User> getFansList(Integer userId){
        if (userId == null) {
            throw new RequestDataException("用户Id获取异常");
        }
        return interestMapper.selectFansList(userId);
    }



    /**
     * 获取用户关注列表
     * @param userId 用户ID
     * @return 简洁用户对象列表
     */
    @Override
    public List<ConciseUserDto> getLike(Integer userId) {
        if (userId == null) {
            return null;
        }
        return interestMapper.selectLikes(userId);
    }

    /**
     * 获取用户粉丝列表
     * @param userId 用户ID
     * @return 简洁用户对象列表
     */
    @Override
    public List<ConciseUserDto> getFans(Integer userId) {
        if (userId == null) {
            return null;
        }
        return interestMapper.selectFans(userId);
    }

    @Override
    public boolean isLike(Integer userId, Integer likeUserId) {
        if (userId == null || likeUserId == null) {
            return false;
        }
        Interest interest = interestMapper.selectLike(userId, likeUserId);
        return interest != null;
    }
}
